package com.ruoyi.onlinevideo.service.impl;/**
 * @InterfaceName: MeetingServiceImpl
 * @Description:
 * @Author: YourName
 * @Date: 2023-04-18
 */

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.onlinevideo.domain.Meeting;
import com.ruoyi.onlinevideo.mapper.MeetingMapper;
import com.ruoyi.onlinevideo.service.MeetingService;
import net.sf.jsqlparser.util.validation.metadata.DatabaseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 *@InterfaceName: MeetingServiceImpl
 *@Description:
 *@Author: lilirui
 *@Date: 2023-04-18
 */
@Service
public class MeetingServiceImpl extends ServiceImpl<MeetingMapper, Meeting> implements MeetingService {

    @Autowired
    MeetingMapper meetingMapper;

    public void updateState(){
        LambdaQueryWrapper<Meeting> meetingLambdaQueryWrapper = new LambdaQueryWrapper<>();
        List<Meeting> list = this.list(meetingLambdaQueryWrapper.eq(Meeting::getState, 0).or().eq(Meeting::getState, 1));
        Date date = new Date();
        for (Meeting meeting : list) {
            if (meeting.getStartTime().getTime()<date.getTime()) {//进行中
                meeting.setState("进行中");
            }
            if (meeting.getEndTime().getTime()<date.getTime()) {//进行中
                meeting.setState("已结束");
            }
        }
        this.updateBatchById(list);
    }

    @Override
    public <E extends IPage<Meeting>> E page(E page, Wrapper<Meeting> queryWrapper) {
        return (E) meetingMapper.selectMeetingPage((Page) page,queryWrapper);
    }
}
